package com.orange.core.service.coupon;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orange.core.mapper.coupon.CouponCategoryMapper;
import com.orange.core.mapper.coupon.CouponMapper;
import com.orange.core.pojo.entity.coupon.Coupon;
import com.orange.core.pojo.entity.coupon.CouponCategory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class CouponCategoryService extends ServiceImpl<CouponCategoryMapper, CouponCategory> {

    private final CouponMapper couponMapper;

    public boolean del(int id) {
        Long couponCount = couponMapper.selectCount(new LambdaQueryWrapper<Coupon>()
                .eq(Coupon::getCategoryId, id));
        Assert.equals(couponCount, 0L, "优惠券分类下还有优惠券，无法删除");

        return this.removeById(id);
    }
}
